<!--<html>-->
<% var cname = 'Contest'; %>
<fieldset>
  <div>
    <legend id="contest" type="<%= type %>">
      <% if (type == 1) { %>
      DIY Contest
      <% } else if (type == 2) { %>
      VIP Contest
      <% } else { %>
      考试
      <% } %>
    </legend>
  </div>
  <div class="tablebg">
    <div id="pager">
      <%- partial('pager', {page:page, n:n}) %>
      <div class="fr" id="filter">
        <div>
          <% if (user) { %>
          <a href="/addcontest?type=<%= type %>" class="uibtn uibtn-mini">Add <%= cname%></a>
          <% } else { %>
          <a href="javascript:;" class="uibtn uibtn-mini checklogin" id="addcontest">Add <%= cname%></a>
          <% } %>
        </div>
        <div class="input-prepend">
          <span class="add-on"><i class="icon-search"></i></span>
          <input type="text" id="search" <% if (search) { %>value="<%= search %>"<% } %> title="Title or Manager" placeholder=" title or manager">
        </div>
        <div>
          <a class="uibtn uibtn-mini" href="javascript:;" id="fil">Filter</a>
        </div>
        <div>
          <a class="uibtn uibtn-mini" href="javascript:;" id="reset">Reset</a>
        </div>
      </div>
    </div>
    <div id="tablediv">
      <table class="table table-cf" id="contest">
        <thead>
          <tr>
            <th style="width:65px;">#</th>
            <th>Title</th>
            <th style="width:180px;">Start Time</th>
            <th style="width:100px;">Duration</th>
            <th style="width:100px;">Type</th>
            <th style="width:100px;">
            <% if (type != 2) { %>Manager<% } %>
            </th>
          </tr>
        </thead>
        <tbody>
          <% if (!contests || contests.length == 0) { %>
          <tr class="odd">
            <td class="error-text" colspan="6">No Contests are matched.</td>
          </tr>
          <% } else { %>
          <% contests.forEach(function(p, i){ %>
          <% var c, dd, hh, mm, s = ''; %>
          <% if (i % 2 == 1) { %>
          <% c = 'even'; %>
          <% } else { %>
          <% c = 'odd'; %>
          <% } %>
          <% dd = parseInt(p.len/1440, 10); hh = parseInt(p.len%1440/60, 10); mm = p.len%1440%60; %>
          <% if (hh < 10) hh = '0'+hh; %>
          <% if (mm < 10) mm = '0'+mm; %>
          <% if (T[i] <= 0) { %>
            <% if (T[i] + p.len*60000 > 0) { %>
            <% s = 'progress-danger'; %>
            <% } else { %>
            <% s = 'progress-success'; %>
            <% } %>
          <% } %>
          <tr class="<%= c %>">
            <td><%= p.contestID %></td>
            <td style="text-align:left;">
              <% if (type != 2 && p.password && (!user || (user.name != p.userName && user.name != 'admin')) && !CS[p.contestID]) { %>
              <a href="javascript:;" class="cid" id="<%= p.contestID %>">
              <% } else { %>
              <a href="/onecontest/<%= p.contestID %>">
              <% } %>
                <%= p.title %>
              </a>
              <% if (type == 2) { %>
              <div class="table-tab">
                <% if (p.password && user && user.name == 'admin') { %>
                <a class="standings" href="/onecontest/<%= p.contestID %>#rank" title="查看排名">Standings</a>
                <% } else if (!s) { %>
                  <% if (R[i]) { %>
                  <span class="user user-green">Registration Completed</span>
                  <% } else { %>
                    <% if (p.password) { %>
                    <span class="user user-gray">Not Registered</span>
                    <% } else { %>
                      <% T[i] -= 300000; %>
                      <% if (T[i] < 0) { %>
                      <span class="user-gray">Registration Closed</span>
                      <% } else { %>
                      Until Closed:
                      <span class="user-gray" style="margin-right:20px;"></span>
                      <a href="javascript:;" class="public register" id="<%= p.contestID %>" left="<%= T[i]/1000 %>">Register &gt;&gt;</a>
                      <% } %>
                    <% } %>
                  <% } %>
                <% } else { %>
                  <a class="standings" href="/onecontest/<%= p.contestID %>#rank" title="查看排名">Standings</a>
                <% } %>
              </div>
              <% } %>
            </td>
            <td>
              <%= getDate(p.startTime) %>
              <div class="progress progress-striped active <%= s %>">
                <div class="bar"></div>
              </div>
            </td>
            <td>
              <% if (dd > 0) { %><%= dd %>天 <% } %><%= hh %>:<%= mm %>:00
            </td>
            <td>
              <% if (p.password) { %>
              <span class="user-green">Private</span>
              <% } else { %>
              <span class="user-blue">Public</span>
              <% } %>
            </td>
            <td>
              <% if (type == 2) { %>
              <img src="/img/user.png" /><a href="/ranklist?cid=<%= p.contestID %>">×<%= p.contestants.length %></a>
              <% } else { %>
              <a class="user user-<%= UC[p.userName] %>" title="<%= UT[p.userName] %>" href="/user/<%= p.userName %>"><%= p.userName %></a>
              <% } %>
            </td>
          </tr>
          <% }); %>
          <% } %>
        </tbody>
      </table>
    </div>
  </div>
</fieldset>